<template>
  <div class="p-2">
    <el-row :gutter="20">
      <el-col :lg="24" :xs="24">
        <div v-show="showSearch" class="mb-[10px]">
          <el-card shadow="hover">
            <el-form ref="queryFormRef" :model="queryParams" :inline="true">
              <el-row :gutter="20">
                <template v-for="(item, index) in searchCol">
                  <template v-if="false"></template>
                  <template v-else>
                    <el-col :span="6">
                      <el-form-item :label="item.label" :prop="item.key">
                        <el-input v-model="queryParams[item.key]" :placeholder="`请输入${item.label}`" clearable @keyup.enter="handleQuery" />
                      </el-form-item>
                    </el-col>
                  </template>
                </template>
                <el-col :span="6">
                  <el-form-item>
                    <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                    <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-card>
        </div>

        <el-card shadow="hover">
          <template #header>
            <el-row :gutter="10">
              <el-col :span="1.5">
<!--                <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>-->
              </el-col>
              <right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
            </el-row>
          </template>

          <el-table v-loading="loading"
                    border
                    :data="listData"
                    @selection-change="handleSelectionChange"
                    :height="showSearch? `calc(100vh - ${ 325 + searchHeight() }px)`: `calc(100vh - ${ 254 + searchHeight() }px)`"
          >
            <el-table-column type="selection" width="50" align="center" />
            <template v-for="(item, index) in columns">
              <el-table-column v-if="item.visible" :key="item.key" :label="item.label" align="center" :prop="item.key" >
                <template v-slot="scope">

                </template>
              </el-table-column>
            </template>

            <el-table-column label="操作" fixed="right" width="180" align="center">
              <template #default="scope">
                <el-button link type="primary" icon="Edit" @click="handleEdit(scope.row)">修改</el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            :total="total"
            @pagination="getList"
          />
        </el-card>
      </el-col>
    </el-row>

  </div>
</template>

<script setup>
// 方法
import { ref } from 'vue'
import methods from '@/utils/methods.js';

// 接口
// import { listLaber } from '@/api/goods/label/index.js'

const formRef = ref(null)

// 搜索列
const searchCol = [
  { key: 'name', label: `访客姓名`, visible: true, children: [] },
  { key: 'interviewee', label: `被访人`, visible: true, children: [] },
]
// 显示与隐藏的搜索高度
const searchHeight = () => {
  let long = searchCol.length + 1
  return Math.floor(long / 4) * 44
}

// 列显隐信息
const columns = ref([
  { key: 'name', label: `姓名`, visible: true, children: [] },
  { key: 'phone', label: `手机号`, visible: true, children: [] },
  { key: 'idNumber', label: `证件号`, visible: true, children: [] },
  { key: 'visitingTime', label: `拜访时间`, visible: true, children: [] },
  { key: 'interviewee', label: `被访人`, visible: true, children: [] },
  { key: 'employeeId', label: `被访人工号`, visible: true, children: [] },
  { key: 'subject', label: `事由`, visible: true, children: [] },
]);

const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
})
const total = ref(0)
const showSearch = ref(true);
const loading = ref(true);
const listData = ref([]);


// 获取数据
const getList = () => {
  loading.value = false
  let params = methods.deepClone(queryParams.value)
  // listLaber(params).then(res => {
  //   listData.value = res.rows
  //   total.value = res.total
  // })
}

// 搜索
const handleQuery = () => {
  getList()
}

// 重置
const resetQuery = () => {
  for (let i in queryParams.value) {
    if (i !== 'pageNum' && i !== 'pageSize') {
      queryParams.value[i] = undefined
    }
  }
  handleQuery()
}

// 多选
const handleSelectionChange = () => {
}

// 新增
const handleAdd = () => {
  formRef.value.open()
}

// 编辑
const handleEdit = (data) => {
  formRef.value.edit(data)
}


getList()
</script>
